/** The main file for
 *  JGE. Allows access
 *  to creating new objects
 *  in a more user
 *  friendly manner.
 * 
 *  Also tries to hide most
 *  OpenGL setting up from
 *  the user although some
 *  things like display updates
 *  must be contained within the
 *  file itself.
 * 
 *  Will be added to as more
 *  functions become needed.
 * 
 * @author Andrew
 * LAST UPDATED - Andrew 5/2/12
 */

package jge;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;


public class JGE {
    
    public static double getVelocity(double time) {
        double output = getVelNum(time)*0.15;
        return output;        
    }
    
    public static int getVelNum(double time) {
        double timed;
        if(time > 1500) timed = 1500;
        else timed = time;
        double output = timed/15;
        return (int) output;
    }
    
    // initializes window withthe ability to hve 2d textures which are
    // transparent in places, sets the view and then resets.
    public static void initJGE() {
        // Select the Projection Matrix
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        // Then Reset it
        GL11.glLoadIdentity();
        // Enable 2D textures
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        
        GL11.glClearColor(1, 1, 1, 0);
        // Enable Blending
        GL11.glEnable(GL11.GL_BLEND);
        // Enable texture transparency
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        // Select PM again
	GL11.glMatrixMode(GL11.GL_PROJECTION);
        // Reset it again
	GL11.glLoadIdentity();
        // Set the View point and type
	GLU.gluOrtho2D(0, 900, 0, 800);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
    }
    
    // Create a tank object at x,y
    public static TankObject newTank(double x, double y) {
        TankObject tank = new TankObject(x,y,"cata.png");
        return tank;
    }
    
    // Create a simple box object of varying sprites at x,y
    public static SimpleObject newObject(double x, double y,String sprite) {
        SimpleObject obj = new SimpleObject(x,y,sprite);
        return obj;
    }
    
    // Create a projectile at x,y fired with velocity v and at an angle.
    public static ProjectileObject newMissile(double x, double y, double v, double angle,double wind) {
        ProjectileObject missile = new ProjectileObject(x,y,v,angle,wind);
        return missile;
    }
    
    
    // Resets the depth and Colour buffers
    public static void glBufferReset() {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}